/**
 * @author lijuan wang
 */
package com.ss.cg;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.TypeDeclaration;

import ss.pku.Scope.SourceFileScope;

import ss.pku.util.ASTUtil;
import ss.pku.util.GlobalContainer;

@SuppressWarnings("unused")
public class CallGraphTest extends ASTVisitor {
	/**
	 * CallGraph
	 */
	private List<CallGraph> callGraph=new ArrayList<CallGraph>();
	/**
	 * get CallGraph
	 */
	public  List<CallGraph> getCallGraph() {
		return callGraph;
	}
	
	public CallGraphTest(String path){
		CallGraphBuilder cgb=new CallGraphBuilder();
		//CallGraph g=null;
		
		//called wei liang 
		ArrayList<SourceFileScope> sfss  = ASTUtil.createASTs(path);
		CompilationUnit result=null;
		for(SourceFileScope src:sfss){
			 result = (CompilationUnit) src.getAstTree();
			 if(result.getProblems().length>0){
					System.out.println("the test case has problems:");
					for(IProblem pro:result.getProblems()){
						System.out.println(pro.getMessage());
					}
					return;
				}
			 cgb.getCompilationUnit().put(src.getFileName(), result);
		}
		for(String key:cgb.getCompilationUnit().keySet())
		{
			cgb.getCompilationUnit().get(key).accept(cgb);
		}
		
		this.callGraph=cgb.getCallGraphs();
	}
}
